package org.atlantis.uzw.dao;

import javax.persistence.LockModeType;

import org.atlantis.uzw.entity.Account;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository("accountDao")
public interface AccountDao extends CrudRepository<Account, Long> {

	@Lock(LockModeType.PESSIMISTIC_WRITE)
	@Query("select account from Account account where account.id = ?1")
	Account getForUpdate(long id);

	@Query("select account.coins - ?2 from Account account where account.id=?1")
	int getRemainedCoins(long id, int coins);
}
